from testcase.markettest import mainmodole
import time,os,xlrd
from common.login import Login
from common.report_generate import Report
class do_case:
    def __init__(self):
        self.st = Login()
        self.driver = self.st.driver

    def read_excel_test(self, sheets):
        filepath = os.path.abspath('../')
        filename = filepath + "/data/case.xlsx"
        excel = xlrd.open_workbook(filename)
        sheet = excel.sheet_by_name(sheets)
        r_num = sheet.nrows
        print(f'共有{r_num}行')
        for r in range(1, r_num):
            print(f'开始第{r}次测试')
            row_info = sheet.row_values(r)
            print(row_info)
            # 获取登录用户，并登录
            mainmodole.load(self, row_info[1])

            # 读取主模块，子模块
            time.sleep(1)
            mod = row_info[2].split('\n')
            a, b = mod[0], mod[1]
            mainmodole.module(self, a, b)

            # 读取操作
            time.sleep(1)
            do = row_info[3].split('\n')
            for i in range(len(do)):
                step = do[i].split(',')
                # print(step)
                tools, way, data, values = step[0], step[1], step[2], step[3]
                # print(tools, way, data, values)
                mainmodole.dosomething(self, tools, way, data, values)
                time.sleep(1)
                a = self.driver.find_element_by_xpath('//*[@id="netCus-table"]/tbody/tr[1]/td[2]').text
                # print(a)

            time.sleep(1)
            # 断言
            asts = row_info[4].split(',')
            # print(asts)
            method,data,value = asts[0],asts[1],asts[2]
            mainmodole.doassert(self,method, data, value, r)
            time.sleep(3)
            self.driver.close()





if __name__ == '__main__':
    do = do_case()
    do.read_excel_test('case')